|
|
@@ -41,7 +41,6 @@ def DJANGO_WE_SHARE_FUNC(request, state=None):
|
41
|
41
|
def DJANGO_WE_MESSAGE_CALLBACK_FUNC(request, data, decrypted=None):
|
42
|
42
|
""" WeChat Message Callback Func """
|
43
|
43
|
|
44
|
|
-
|
45
|
44
|
def DJANGO_WE_COMPONENT_CALLBACK_FUNC(request, appid, data, decrypted=None):
|
46
|
45
|
""" WeChat Component Message Callback Func """
|
47
|
46
|
from django_we.models import SubscribeUserInfo
|
|
|
@@ -125,18 +124,18 @@ def DJANGO_WE_COMPONENT_CALLBACK_FUNC(request, appid, data, decrypted=None):
|
125
|
124
|
# OrderedDict([(u'ToUserName', u'gh_48cbe3523cf6'), (u'FromUserName', u'oRgy0uH8qHxzwwSC9H7YrRIv5Mxw'), (u'CreateTime', u'1598886287'), (u'MsgType', u'event'), (u'Event', u'subscribe'), (u'EventKey', u'qrscene_book'), (u'Ticket', u'gQHL8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyYWgwVjRSNmNhUVUxMDAwMHcwNzkAAgT8OkxfAwQAAAAA')])
|
126
|
125
|
eventkey = decrypted.get('EventKey', '')
|
127
|
126
|
|
128
|
|
- if event == 'subscribe' or event == 'unsubscribe':
|
129
|
|
- CFG = settings.WECHAT.get('COMPONENT', {})
|
|
127
|
+ CFG = settings.WECHAT.get('COMPONENT', {})
|
130
|
128
|
|
131
|
|
- appid = 'wx75b14576708d330d'
|
|
129
|
+ appid = 'wx75b14576708d330d'
|
132
|
130
|
|
133
|
|
- # 获取第三方平台token
|
134
|
|
- token = authorizer_access_token(
|
135
|
|
- component_appid=CFG['appID'],
|
136
|
|
- component_secret=CFG['appsecret'],
|
137
|
|
- authorizer_appid=appid,
|
138
|
|
- storage=RedisStorage(r)
|
139
|
|
- )
|
|
131
|
+ # 获取第三方平台token
|
|
132
|
+ token = authorizer_access_token(
|
|
133
|
+ component_appid=CFG['appID'],
|
|
134
|
+ component_secret=CFG['appsecret'],
|
|
135
|
+ authorizer_appid=appid,
|
|
136
|
+ storage=RedisStorage(r)
|
|
137
|
+ )
|
|
138
|
+ if event == 'subscribe' or event == 'unsubscribe':
|
140
|
139
|
|
141
|
140
|
# 获取用户信息
|
142
|
141
|
userinfo = get_user_info(openid, appid=appid, secret=None, token=token, storage=RedisStorage(r))
|
|
|
@@ -163,21 +162,6 @@ def DJANGO_WE_COMPONENT_CALLBACK_FUNC(request, appid, data, decrypted=None):
|
163
|
162
|
'remark': userinfo.get('remark', ''),
|
164
|
163
|
})
|
165
|
164
|
|
166
|
|
- # 关注后
|
167
|
|
- # 发送客服消息 - 发送小程序卡片
|
168
|
|
- # TODO: miniappid、pagepath、thumb_media_id、title
|
169
|
|
- # send_custom_wxa_message(
|
170
|
|
- # openid=openid,
|
171
|
|
- # miniappid=miniappid,
|
172
|
|
- # pagepath=pagepath,
|
173
|
|
- # thumb_media_id=thumb_media_id,
|
174
|
|
- # title=title,
|
175
|
|
- # appid=appid,
|
176
|
|
- # secret=None,
|
177
|
|
- # token=token,
|
178
|
|
- # storage=RedisStorage(r)
|
179
|
|
- # )
|
180
|
|
-
|
181
|
165
|
else:
|
182
|
166
|
SubscribeUserInfo.objects.using('hanyuan').filter(openid=openid).update(subscribe=subscribe)
|
183
|
167
|
|
|
|
@@ -185,16 +169,42 @@ def DJANGO_WE_COMPONENT_CALLBACK_FUNC(request, appid, data, decrypted=None):
|
185
|
169
|
if eventkey:
|
186
|
170
|
scene = parse_eventkey(eventkey, event='subscribe')
|
187
|
171
|
if scene:
|
188
|
|
- send_custom_card_message(
|
|
172
|
+ params = scene.split(':')
|
|
173
|
+ send_custom_wxa_message(
|
189
|
174
|
openid=openid,
|
190
|
|
- card_id=settings.DJANGO_WE_MEMBER_CARD_ID,
|
|
175
|
+ miniappid='wxc0dec29f0c358493',
|
|
176
|
+ pagepath='/pages/registration/course/course?field_id={}&admin_id={}'.format(params[0], params[1]),
|
|
177
|
+ thumb_media_id='Wgff8-suDh0aD_m_XBWWy6tykwlx72Wo1Ea38nOxsCQIlvVHM_9oxoAp82XRdsJh',
|
|
178
|
+ title='报名课程',
|
|
179
|
+ appid=appid,
|
|
180
|
+ secret=None,
|
|
181
|
+ token=token,
|
|
182
|
+ storage=RedisStorage(r)
|
|
183
|
+ )
|
|
184
|
+ # send_custom_card_message(
|
|
185
|
+ # openid=openid,
|
|
186
|
+ # card_id=settings.DJANGO_WE_MEMBER_CARD_ID,
|
|
187
|
+ # appid=appid,
|
|
188
|
+ # secret=None,
|
|
189
|
+ # token=token,
|
|
190
|
+ # storage=RedisStorage(r)
|
|
191
|
+ # )
|
|
192
|
+ elif event == 'SCAN':
|
|
193
|
+ if eventkey:
|
|
194
|
+ scene = parse_eventkey(eventkey, event='SCAN')
|
|
195
|
+ if scene:
|
|
196
|
+ params = scene.split(':')
|
|
197
|
+ send_custom_wxa_message(
|
|
198
|
+ openid=openid,
|
|
199
|
+ miniappid='wxc0dec29f0c358493',
|
|
200
|
+ pagepath='/pages/registration/course/course?field_id={}&admin_id={}'.format(params[0], params[1]),
|
|
201
|
+ thumb_media_id='Wgff8-suDh0aD_m_XBWWy6tykwlx72Wo1Ea38nOxsCQIlvVHM_9oxoAp82XRdsJh',
|
|
202
|
+ title='报名课程',
|
191
|
203
|
appid=appid,
|
192
|
204
|
secret=None,
|
193
|
205
|
token=token,
|
194
|
206
|
storage=RedisStorage(r)
|
195
|
207
|
)
|
196
|
|
-
|
197
|
|
-
|
198
|
208
|
def DJANGO_WE_REDIS_OBJ_FUNC(request):
|
199
|
209
|
""" WeChat Redis Object Callback Func """
|
200
|
210
|
from utils.redis.connect import r
|